/***************************************************************************
 * This program is free software; you can redistribute it and/or           *
 * modify it under the terms of the GNU General Public License             *
 * as published by the Free Software Foundation; either version 2          *
 * of the License, or (at your option) any later version.                  *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License       *
 * along with this program; if not, write to the Free Software Foundation, *
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         *
 *                                                                         *
 *   Copyright (C) 2007,2008 by Ivan Vucica                                *
 *   ivucica@gmail.com                                                     *
 ***************************************************************************/


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <sstream>
#include <string>
#include <vector>
#include <stdarg.h>

#include "procedure.h"
#include "token.h"
#include "primlib.h"
#include "logocontext.h"
#include "logosource.h"
#include "logointerpreter.h"


void onlogo_printf (const char* txt, ...) {
	va_list vl;
	va_start(vl, txt);
	vprintf(txt, vl);
	va_end(vl);
}

int main()
{
    	//LogoSource kodos = "asgard    make \"a \"crtic make :a 5  (jedan (drugi skup)) [lista (jest [vrlo kul)] ]  \"a  \"antoan\\ djepic 52 \n\"bekavac.smrkalj+";
	//kodos.Dump();

	LogoContext globalcontext;

	/*LogoInterpreter kod = "PRINT \"bok "
	"POTS  "
	"MAKE \"a 2 "
	"MAKE \"b (2+2)*:a "
	"MAKE \"c 5-:a+3 "
	"__VARIABLES "
	"(PRINT \"huja \"hoj :a :b :c :d)"

	;*/

	/*LogoInterpreter kod =
	"TO PROBA :a :b :c\n"
	"PRINT \"HELLO\n"
	"FOR \"I 1 50 [PRINT [hello world] PRINT (2+2*2)] PRINT 2*(2+2) PR :a\n"
	"END\n"

	"POTS\n"
	"TO PROBA :a :b :c\n"
	"PRINT \"HELLO\n"
	"PRINT 2*(2+2) PR :a PR \"ante\\ portas\n"
	"END\n"


	"PROBA 1 2 3\n"
	;*/

	/*LogoInterpreter kod =
	"MAKE \"a [b c] "
	"PR :a "
	"REPEAT 4 [PR \"A] "
	;*/


	LogoInterpreter kod = "PRINT -1"
	;

	kod.Dump();
	printf("-------------------\n");
	globalcontext.RegisterProcedure(std::string("PRINT"), prm_print , 1);
	globalcontext.RegisterProcedure(std::string("PR"), prm_print , 1);
	globalcontext.RegisterProcedure(std::string("POTS"), prm_pots , 0);
	globalcontext.RegisterProcedure(std::string("__VARIABLES"), prm___variables , 0);
	globalcontext.RegisterProcedure(std::string("MAKE"), prm_make, 2);
	globalcontext.RegisterProcedure(std::string("REPEAT"), prm_repeat, 2);
	globalcontext.RegisterProcedure(std::string("BYE"), prm_bye, 0);

	try {
		kod.Execute(globalcontext);
	} catch (std::string s) {
		printf("Exception: %s\n", s.c_str());
	}
	getchar();
	return 0;
}
